package com.lc.big_event.controller;

import com.lc.big_event.pojo.Category;
import com.lc.big_event.pojo.Result;
import com.lc.big_event.service.CategoryService;
import com.lc.big_event.untils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author liuchun
 */
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @PostMapping
    public Result add(@RequestBody @Validated(Category.Add.class) Category category){
        categoryService.add(category);
        return Result.success();
    }

    @GetMapping
    public Result<List<Category>> list(){
       List<Category> cs = categoryService.list();
       return Result.success(cs);
    }

    @GetMapping("/detail")
    public Result<Category> detail(@RequestParam Integer id){
        Category cd = categoryService.detail(id);
        return Result.success(cd);
    }
    /**
     * 更新文章分类
     */
    @PutMapping
    public Result updateArticle(@RequestBody @Validated(Category.Update.class) Category category){
        categoryService.updateArticle(category);
        return Result.success();
    }
    /**
     * 删除文章分类
     */
    @DeleteMapping
    public Result delete(@RequestParam Integer id){
        categoryService.delete(id);
        return Result.success();
    }
}
